11610. Cost of letters

 

Consider a text. Only capital Latin letters from A to Z have a cost. The cost of A is 1, cost of B is 2 and so on. The cost of Z is 26. Find the product of all costs of letters in the text.

 

Input. Text that consists of multiple lines and can contain any letters.

 

Output. Print the product of all costs of letters in the text by modulo 109 + 7.

 

Sample input

Sample output

Eolymp chapter VI

    plus ,.,.

$%4  $56 $^ USAco 456$%^$

4%^$^

395010

 

SOLUTION

strings

 

Algorithm analysis

Process the letters of the text sequentially. If the current letter is a capital Latin letter, then find its cost. Find the product of all the costs of the letters in the text by modulo 109 + 7.

 

Example

In the given example we have the next capital Latin letters: E (5), V (22), I (9), U (21), S (19), A (1). The costs of the letters are given in the brackets. The product of all the costs is (5 22 9 21 19 1) mod 1000000007 = 395010.

 

Algorithm realization

Let’s define the modulo by which we’ll calculate the product.

 

#define MOD 1000000007

 

The required product will be computed in the variable res.

 

res = 1;

 

Read the text line by line.

 

while (getline(cin, s))

{

 

Process the current line s.

 

  for (i = 0; i < s.size(); i++)

  {

 

If the current symbol s[i] is an uppercase Latin letter, then find its cost c. Multiply res by c.

 

    if (('A' <= s[i]) && (s[i] <= 'Z'))

    {

      c = s[i] - 'A' + 1;

      res = (res * c) % MOD;

    }

  }

}

 

Print the answer.

 

cout << res << endl;